﻿<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<meta content="telephone=no" name="format-detection" />
		<meta content="email=no" name="format-detection" />
		<title>登录</title>
		<link rel="stylesheet" href="css/s_plus.css" />
		<link rel="stylesheet" href="css/base.css" />
		<link rel="stylesheet" href="css/layout.css" />
		<link rel="stylesheet" href="css/choice.css" />
		<link rel="stylesheet" type="text/css" href="css/hui.css" />

		<script type="text/javascript" src="libs/vue.js"></script>
		<script type="text/javascript" src="js/jquery.1.9.1.min.js"></script>
		<script type="text/javascript" src="js/app/url.js"></script>
		<script type="text/javascript" src="js/md5.js"></script>
		<script type="text/javascript" src="js/hui.js"></script>
		<script type="text/javascript" src="js/app/api.js?v=22"></script>
		<script type="text/javascript" src="js/app/my.js"></script>
		<script type="text/javascript" src="js/app/url.js"></script>
		<script type="text/javascript" src="js/mui.min.js"></script>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=a82yNQICnHARgGpKuPH1wWZWQcBD2Llo"></script>


	</head>

	<body  class="login_bg">
		<div class="f_l login" id="app">
			<h1 class="t_c"><img width="200" src="images/icon.png" /></h1>
			<ul>
				<li>
					<b><i class="iconfont">&#xe619;</i></b>
					<input class="input_txt" name="" v-model="username" type="text" value="" placeholder="请输入用户名">
				</li>
				<li>
					<b><i class="iconfont">&#xe62f;</i></b>
					<input class="input_txt" name="" v-model="pwd" type="password" value="" placeholder="请输入密码">
				</li>
				<!--<li class="t_c">&nbsp;<em v-text="info"></em>&nbsp;</li>-->
				<li><input class="btn" name="" type="button" @click="loginInfo" value="登录"></li>
				<li>
					<p class="checkbox checkbox_primary">
						<input name="choice1" id="checkbox1"  type="checkbox" :checked="keepStatus">
						
						<label for="checkbox1">记住密码</label>

					</p>
					<a class="password" @click="forgetPwd">忘记密码？</a>
				</li>
			</ul>
		</div>
		<script>
			
			


            	mui.plusReady(function() {

			var old_back = mui.back;
		mui.back = function(){
		  
		  plus.runtime.quit()

		 }
		
	
	    if(isTest){
	    	hui.toast("天联城市智慧测试版");
	    }


				//定时刷新
				var walk = function() {
					getGeocode();
					console.log(apiManage.getNowFormat() + '    Hello');

				}
				//		setInterval(walk,3000); 

				//		wx340429690697154560
				//		123456
				//ydwxy01
				var vm = new Vue({
					el: "#app",
					data: {
						params: {
							longitude: "",
							latitude: "",
							"userId.id": ""
						},
						username: "",
						pwd: "",
						keep: [],
						info: "",
						disable_code: false,
						keepStatus:""
						//					checked:false
					},

					mounted: function() {
						var keep_param = localStorage.getItem("keep");
					
					
						console.log("keep_param-" + keep_param);
						if(keep_param == 'true') { //保存密码 则显示

						this.keepStatus="checked";

							this.username = localStorage.getItem("username");
							this.pwd = localStorage.getItem("password");
						} else { //清空
							//						console.log("清空");

//							this.username = "";
							this.username = localStorage.getItem("username");

							this.pwd = "";
						}

					},
					methods: {

						forgetPwd: function() {
							localStorage.setItem("paramUsername", this.username);
							hui.open("modules/login/forgetPwd.html", {}, true, {});
						},

						sendCode: function() {
							//this.showAll();
							if(vm.disable_code) {
								return;
							}
							var tel = this.phone; //获取手机号
							var telReg = !!tel.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
							//如果手机号码不能通过验证
							if(telReg == false) {
								// alert('请输入合法的手机号');
								this.info = '请输入合法的手机号';

								return;
							}

							if(isEmpty(this.username)) {
								this.info = '请输入姓名';
								return;
							}

						},

						getKeep: function(event) {
							console.log("是否要保存密码------"+this.keep);
						},
						saveSecret: function(username, sec) { //将用户名 加密密钥存到本地

							console.log("保存的username----" + username);
							localStorage.setItem("username", username);
							localStorage.setItem("sec_pwd", sec);

						},
						loginInfo: function() {
							vm.info = "";

							if(isEmpty(this.username)) {
								vm.info = "用户名不能为空";
								hui.toast("用户名不能为空");
								return;
							}

							if(isEmpty(this.pwd)) {
								vm.info = "密码不能为空";
								hui.toast("密码不能为空");

								return;
							}

							var path = urlManager.loginInfo() + "?loginName=" + this.username + "&passWord=" + this.pwd + "&time=" + apiManage.getNow();
							console.log(path);
							hui.loading("");

							$.ajax({
								timeout: 10000,
								type: "GET",
								url: path,
								error: function(xhr, textStatus) {
									console.log("error----------" + textStatus);
									hui.closeLoading();

									if(textStatus == 'timeout') {
										//处理超时的逻辑
										hui.toast("网络超时，请重试");
									} else {
										//其他错误的逻辑
										hui.toast("服务器无法连接，请重试");
									}
								},
								success: function(ret) {
									console.log("登录返回数据:" + JSON.stringify(ret));

									if(ret.id == null) {
										hui.closeLoading();
										hui.toast('用户名或密码错误', 2);
										return;
									}

									if(ret.id == null && ret.remarks != null) {
										hui.closeLoading();
										hui.toast(ret.remarks, 2);
										return;
									}

									setInterval(walk, 2 * 60 * 1000); //5分钟(单位ms )执行一次

									setTimeout(function(){
										walk();
									},2000);

									vm.$options.methods.saveSecret(ret.loginName, ret.passWordStr);
									localStorage.setItem("userid", ret.id);
									localStorage.setItem("officeId", ret.officeId);
									localStorage.setItem("companyId", ret.companyId);

									localStorage.setItem("menuMap", JSON.stringify(ret.menuMap));

									hui.closeLoading();

									if($("#checkbox1").get(0).checked) { //保存
										//									console.log('保存');
										localStorage.setItem("keep", "true");
									} else { //不保存
										localStorage.setItem("keep", "false");
										//localStorage.setItem("password", "");
										//									console.log('不保存');
									}
									localStorage.setItem("password", vm.pwd);

									var config = apiManage.getMenuConfig();
									var cell = config[0];
									hui.open(cell.url + "?date=" + apiManage.getNow(), {}, true, {});
									//								console.log("登陆后跳转URL ----" + cell.url)
									//								console.log("localStorage--" + JSON.stringify(localStorage));

								}
							});

						}
					}

				});
				

				// 通过定位模块获取位置信息
				function getGeocode() {
					//hui.loading("定位中");
					plus.geolocation.getCurrentPosition(showLocation, function(e) {
						//						hui.toast("获取定位位置信息失败：" + e.message);
						console.log("获取定位位置信息失败：" + e.message);
					}, {
						geocode: true,
						provider:'baidu',
						coordsType:'bd09ll',
					});
				}

				//处理定位后的信息
				function showLocation(r) {
//				    console.log("定位" + JSON.stringify(r));

					var lng = r.coords.longitude;
					var lat = r.coords.latitude;

					vm.params.longitude=lng;
				    vm.params.latitude=lat;

					var address = r.addresses;
//					console.log("定位位置：   " + address);
					//centerPointer = new BMap.Point(r.coords.longitude, r.coords.latitude);
					//exchange();

					sendLocation();
				}

				//将GPS坐标转换成百度地图的坐标
				function exchange() {
					var convertor = new BMap.Convertor();
					var pointArr = [];
					pointArr.push(centerPointer);
					convertor.translate(pointArr, 1, 5, translateCallback);
				}

				function translateCallback(data) {
					if(data.status == 0) {
						var paramPoint = data.points[0];
						vm.params.longitude = String(paramPoint.lng);
						vm.params.latitude = String(paramPoint.lat);
						sendLocation();
					}
				}

				//上传定位信息
				function sendLocation() {

					var path = urlManager.saveUserTrajectory();
//					console.log(path);
					var username = localStorage.getItem("username");
					var sec = localStorage.getItem("sec_pwd");
					var time = apiManage.getNow();
					var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
					//	   	console.log(key);
					var paramKey = hex_md5(key);

					var userid = localStorage.getItem("userid");
					vm.params["userId.id"] = userid;

//					console.log("path============================" + path);
//					console.log("params===================" + JSON.stringify(vm.params));
					hui.loading("数据上传中..");
					$.ajax({
						type: "POST",
						url: path,
						data: vm.params,
						beforeSend: function(request) {
							request.setRequestHeader("loginName", username);
							request.setRequestHeader("time", time);
							request.setRequestHeader("sign", paramKey);
						},
						success: function(result) {
							console.log("主动上传返回============================" + JSON.stringify(result));
							hui.closeLoading();
							console.log("主动定位成功");
							

						}
					});

				}

				//获取当前时间戳
				function getNow() {
					var timestamp = new Date().getTime();
					return timestamp;
				}

				//判断字符是否为空的方法
				function isEmpty(obj) {
					if(typeof obj == "undefined" || obj == null || obj == "") {
						return true;
					} else {
						return false;
					}
				}

			})
            	
            	  
			
		</script>
	</body>

</html>